class SessionsController < ApplicationController
  def new
    render layout: false
  end

  def create
    user = User.find_by(email: params[:session][:email].downcase)
    if user && user.authenticate(params[:session][:password])
      # 登入用户，然后重定向到用户的资料页面
      log_in user
      puts current_user.name
      redirect_to root_path
    else
      # 创建一个错误消息
      render 'new', layout: false
    end
  end

  def show
    @user = User.find(params[:id])
  end

  def destroy
    log_out
    redirect_to login_path
  end

end
